package com.ruoyi.truth.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.truth.domain.TruReport;
import com.ruoyi.truth.service.ITruReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 信用报告Controller
 * 
 * @author ruoyi
 * @date 2023-07-05
 */
@RestController
@RequestMapping("/truth/report")
public class TruReportController extends BaseController
{
    @Autowired
    private ITruReportService truReportService;

    /**
     * 查询信用报告列表
     */
    @PreAuthorize("@ss.hasPermi('truth:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(TruReport truReport)
    {
        startPage();
        List<TruReport> list = truReportService.selectTruReportList(truReport);
        return getDataTable(list);
    }

    /**
     * 导出信用报告列表
     */
    @PreAuthorize("@ss.hasPermi('truth:report:export')")
    @Log(title = "信用报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TruReport truReport)
    {
        List<TruReport> list = truReportService.selectTruReportList(truReport);
        ExcelUtil<TruReport> util = new ExcelUtil<TruReport>(TruReport.class);
        util.exportExcel(response, list, "信用报告数据");
    }

    /**
     * 获取信用报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('truth:report:query')")
    @GetMapping(value = "/{truId}")
    public AjaxResult getInfo(@PathVariable("truId") Long truId)
    {
        return success(truReportService.selectTruReportByTruId(truId));
    }

    /**
     * 新增信用报告
     */
    @PreAuthorize("@ss.hasPermi('truth:report:add')")
    @Log(title = "信用报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TruReport truReport)
    {
        return toAjax(truReportService.insertTruReport(truReport));
    }

    /**
     * 修改信用报告
     */
    @PreAuthorize("@ss.hasPermi('truth:report:edit')")
    @Log(title = "信用报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TruReport truReport)
    {
        return toAjax(truReportService.updateTruReport(truReport));
    }

    /**
     * 删除信用报告
     */
    @PreAuthorize("@ss.hasPermi('truth:report:remove')")
    @Log(title = "信用报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{truIds}")
    public AjaxResult remove(@PathVariable Long[] truIds)
    {
        return toAjax(truReportService.deleteTruReportByTruIds(truIds));
    }
}
